package com.simon.adapter;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.cmonbaby.adapter.listview.LCommonAdapter;
import com.cmonbaby.adapter.listview.LViewHolder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<String> mDatas = new ArrayList<>(Arrays.asList("MultiItem ListView",
            "RecyclerView",
            "MultiItem RecyclerView"));
    private ListView mListView;
    private View mEmptyView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mListView = ((ListView) findViewById(R.id.id_listview_list));
        mEmptyView = findViewById(R.id.id_empty_view);
        mListView.setAdapter(new DemoAdapter(R.layout.item_list, mDatas));

        mListView.setEmptyView(mEmptyView);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                    default:
                        Log.e("click", "MultiItemListViewActivity");
                        startActivity(new Intent(getApplicationContext(), MultiItemListViewActivity.class));
                        break;
                    case 1:
                        Log.e("click", "RecyclerViewActivity");
                        startActivity(new Intent(getApplicationContext(), RecyclerViewActivity.class));
                        break;
                    case 2:
                        Log.e("click", "MultiItemRvActivity");
                        startActivity(new Intent(getApplicationContext(), MultiItemRvActivity.class));
                        break;

                }
            }
        });
    }

    private class DemoAdapter extends LCommonAdapter<String> {

        public DemoAdapter(int layoutId, List<String> datas) {
            super(layoutId, datas);
        }

        @Override
        protected void convert(LViewHolder lViewHolder, String item, int position) {
            lViewHolder.setText(R.id.id_item_list_title, item);
//            lViewHolder.setOnClickListener(R.id.id_item_list_title, new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Log.e("------ ", "click");
//                }
//            });
        }

        @Override
        public void onViewHolderCreated(LViewHolder holder, View itemView) {
            super.onViewHolderCreated(holder, itemView);
        }
    }

}
